
<#include "/base/common/head.html"/>
    
    <table id="dg"></table>
    <div id="tb" style="padding:2px 5px;">
        <div class="wrap_search">
		        		
			        		<span class="search_item search_between">
				                <span class="item_text">创建时间: </span>
				                <span class="item_obj">
				                    <input class="easyui-datebox" name="date_start" id="date_start" value=""/> ~ <input class="easyui-datebox" name="date_end" id="date_end" value=""/>
				                </span>
				            </span>
		        		
			            	<span class="search_item">
				            	<span class="item_text">类型: </span>
				            	<span class="item_obj">
				            		<input class="easyui-textbox" type="text" name="type" id="type" value=""/>
				            	</span>    
				            </span>
		        		
			            	<span class="search_item">
				            	<span class="item_text">小类: </span>
				            	<span class="item_obj">
				            		<input class="easyui-textbox" type="text" name="typeTwo" id="typeTwo" value=""/>
				            	</span>    
				            </span>
				            
			            	<span class="search_item">
				            	<span class="item_text">日志级别: </span>
				            	<span class="item_obj">
									<input class="easyui-combobox" id="level" name="level"  editable=false 
    									data-options="valueField:'label',textField:'value',data:[{
																							label: 'info',
																							value: 'info'
																						},{
																							label: 'warn',
																							value: 'warn'
																						},{
																							label: 'error',
																							value: 'error'
																						}]" /> 
				            	</span>    
				            </span>
		        		
			            	<span class="search_item">
				            	<span class="item_text">日志内容: </span>
				            	<span class="item_obj">
				            		<input class="easyui-textbox" type="text" name="msg" id="msg" value=""/>
				            	</span>    
				            </span>
        </div>
        <div style="text-align: left; margin:6px;">
        	<!--  
            <a href="javascript:void(0)" class="easyui-linkbutton addBtn" iconCls="glyphicon-plus" plain="true" onclick="add()">增加</a>
            <a href="javascript:void(0)" class="easyui-linkbutton updateBtn" iconCls="glyphicon-pencil" plain="true" onclick="update()">编辑</a>
            <a href="javascript:void(0)" class="easyui-linkbutton exportBtn" iconCls="glyphicon-export" plain="true" onclick="exportCsv()">导出</a>
            -->
            <a href="javascript:void(0)" class="easyui-linkbutton delBtn" iconCls="glyphicon-remove" plain="true" onclick="del()">删除</a>
            <a href="javascript:void(0)" class="easyui-linkbutton detailBtn" iconCls="glyphicon-map-marker" plain="true" onclick="detail()">详情</a>
            <div id="searchBtnWrap" style="float:right; padding-right:40px;">
                <a href="javascript:void(0)" class="easyui-linkbutton color1" iconCls="glyphicon-search" onclick="zcurdSearch(this)">搜索</a>
                <a href="javascript:void(0)" class="easyui-linkbutton color2" iconCls="glyphicon-repeat" onclick="flushPage()">重置</a>
            </div>
        </div>
    </div>
    

<script type="text/javascript">
var datagrid = $("#dg");

var dgOptions = {
        rownumbers:true,
    	fit:true,
    	border:false,
    	url:'listData',
    	method:'post',
    	toolbar:'#tb',
    	pageSize: 20,
    	pagination:true,
    	//fitColumns:true,
    	striped:true,
    	multiSort:true,
    	singleSelect: true,
		ctrlSelect : true,
        queryParams: getInitParam(),
        onDblClickRow:function(index, row){viewData(row.id);},
        
        columns: [[
		         {field:'id', checkbox:true}
	           	 ,{field:'addTime', title: '创建时间', width:140, align:'center'}
	           	 ,{field:'level', title: '日志级别', width:100, align:'center'}
	           	 ,{field:'msg', title: '日志内容', width:300}
	           	 ,{field:'type', title: '类型', width:100, align:'center'}
	           	 ,{field:'typeTwo', title: '小类', width:100, align:'center'}
	           ]],
	      loadFilter: function(data) {
	        	   if(data.result && data.result == 'fail') {	//失败时，错误消息提示
	        		   showWarnMsg(data.msg);
	        		   return {};
	        	   }else {
	        		   return data;
	        	   }
	           }           
	};
$(function() {
	
	datagrid.datagrid(dgOptions);
});


function zcurdSearch() {
	var param = zcurdGetParam();
	/* datagrid.datagrid("load", {
		queryParams: param
	}) */
	
	datagrid.datagrid("load", param)
}

function zcurdGetParam() {
	var param = {};
	$("#tb :input[name]").each(function(i, item) {
		if($(item).val()) {
			param[$(item).attr("name")] = $(item).val();	
		}
	});
	return param;
}

function getInitParam() {
	var param = {};
	$("#tb :input[name]").each(function(i, item) {
		if($(item).val()) {
			param["queryParams[" + $(item).attr("name") + "]"] = $(item).val();	
		}
	});
	return param;
}

var initPara = zcurdGetParam();
function add() {
	top.window.subPage.loadCurrDatagrid = function() {
		showMsg("增加成功");
		datagrid.datagrid("load");
	}
	top.openWindow("发送日志-增加", getCurrUrl("addPage") + "?" + $.param(initPara), {size: '800x600'});
}

function update() {
	var rowsSel = datagrid.datagrid("getSelections");
	if(rowsSel.length != 1) {
		showWarnMsg("请??择需要编辑的????数据");
		return;
	}
	var id = rowsSel[0].id;
	top.window.subPage.loadCurrDatagrid = function() {
		showMsg("更新成功");
		datagrid.datagrid("reload");
	}
	top.openWindow("发送日志-编辑", getCurrUrl("updatePage") + "?id=" + id, {size: '800x600'});
}

function del() {
	var ids = [];
	$.each(datagrid.datagrid("getSelections"), function(i, item) {
		ids.push(item.id);
	});
	if(ids.length < 1) {
		showWarnMsg("请选择需要删除的数据");
		return;
	}
	confirmMsg("确认删除?", function() {
		$.post(getCurrUrl("delete"), {ids: ids.join(",")}, function(data) {
			showMsg("删除成功");
			datagrid.datagrid("reload");
		});
	});
}

function detail() {
	var rowsSel = datagrid.datagrid("getSelections");
	if(rowsSel.length != 1) {
		showWarnMsg("请选择需要查看的一条数据");
		return;
	}
	var id = rowsSel[0].id;
	//top.openWindow("发送日志-详情", getCurrUrl("detailPage") + "?id=" + id, {size: '800x600'});
	viewData(id);
}

function viewData(id)
{
	top.openWindow_view("单据详情", getCurrUrl("detailPage") + "?id=" + id, {size: '800x500'});
}


function exportCsv() {
	var option = datagrid.datagrid("options");
	var param = option.queryParams;
	param.sortName = option.sortName;
	param.sortOrder = option.sortOrder;
	window.location.href = "exportCsv?" + $.param(param);
}

function send() {
	var rowsSel = datagrid.datagrid("getSelections");
	if(rowsSel.length != 1) {
		showWarnMsg("请选择需要查看的一条数据");
		return;
	}
	var id = rowsSel[0].id;
	$.post(getCurrUrl("sendOneBill"), {id: id}, function(data) {
		datagrid.datagrid("reload");
		if(data.code == "01")
		{
			showMsg(data.msg);
		}
		else
		{
			showErrorMsg(data.msg);
		}
		
	});
}

//按钮事件

/**
 * 打开子页
 */
var _openSubPageFlag = false;
function _openSubPage(pageUrl) {
	if(!_openSubPageFlag) {
		$("#subLayout").layout("expand", "east");
		setTimeout(function() {
			$("#subIframe").attr("src", pageUrl);
		}, 600);
		_openSubPageFlag = true;
	}else {
		$("#subIframe").attr("src", pageUrl);
	}
}

//扩展js
//格式化类型对象的输出
function formatType(value)
{
	return value.name;
};


function formatResultType(value)
{
	if(value.code=='01')
	{
		return value.name;
	}
	else
	{
		return "<span style='color:#ff0000'>"+value.name+"</span>";
	}
};

function formatState(value)
{
	if(value==null)
	{
		return "";
	}
	if(value=='待发送')
	{
		return value;
	}
	else
	{
		return "<span style='color:#008B00'>"+value+"</span>";
	}
};

</script>

<#include "/base/common/dialogWindow.html"/>
<#include "/base/common/foot.html"/>
